local huiguo = fk.CreateSkill{
  name = "hanqing__huiguo",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["hanqing__huiguo"] = "隳国",
  [":hanqing__huiguo"] = "锁定技，当你造成或受到伤害后，若受伤角色已损失体力值为：1，你弃置其一张牌；2，你摸两张牌；3或更多，"..
  "你令其减1点体力上限。",

  ["#hanqing__huiguo-discard"] = "隳国：请弃置 %dest 一张牌",
}

local spec = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(huiguo.name) then
      local n = data.to:getLostHp()
      if n == 1 then
        return not data.to:isNude()
      elseif n == 2 then
        return true
      elseif n > 2 then
        return not data.to.dead
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    event:setCostData(self, {tos = {data.to}})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = data.to:getLostHp()
    if n == 1 then
      if data.to == player then
        room:askToDiscard(player, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = huiguo.name,
          cancelable = false,
          prompt = "#hanqing__huiguo-discard::"..player.id,
        })
      else
        local card = room:askToChooseCard(player, {
          target = data.to,
          flag = "he",
          skill_name = huiguo.name,
          prompt = "#hanqing__huiguo-discard::"..data.to.id,
        })
        room:throwCard(card, huiguo.name, data.to, player)
      end
    elseif n == 2 then
      player:drawCards(2, huiguo.name)
    elseif n > 2 then
      room:changeMaxHp(data.to, -1)
    end
  end,
}

huiguo:addEffect(fk.Damage, spec)
huiguo:addEffect(fk.Damaged, spec)

return huiguo
